package uk.ac.lkl.lpp.xml;



import java.util.HashMap;
import java.util.logging.Logger;


/**
 * Some duplication here due to two different types of parameter. Need
 * to fix this. e.g. hierarchy.
 * 
 * 
 * @author Darren Pearce
 * @version $Revision$
 * @version $Date$
 * 
 */
public class ParameterMap {
	private static final Logger logger = Logger.getLogger("uk.ac.lkl.lpp");

    private HashMap<String, String> basicParameters;

    private HashMap<String, HashMap<String, String>> mapParameters;


    public ParameterMap() {
    	logger.entering("ParameterMap", "constructor()");
        basicParameters = new HashMap<String, String>();
        mapParameters = new HashMap<String, HashMap<String, String>>();
    }

    public void setParameter(String parameterName, String parameterValue) {
        basicParameters.put(parameterName, parameterValue);
    }


    public void setMapParameter(String parameterName, String key, String value) {
        HashMap<String, String> mapParameter = mapParameters.get(parameterName);
        if (mapParameter == null) {
            mapParameter = new HashMap<String, String>();
            mapParameters.put(parameterName, mapParameter);
        }
        mapParameter.put(key, value);
    }


    public String getParameterAlways(String parameterName) {
        String parameterValue = basicParameters.get(parameterName);
        return parameterValue;
    }


    public HashMap<String, String> getMapParameterAlways(String parameterName) {
        HashMap<String, String> mapParameter = mapParameters.get(parameterName);
        return mapParameter;
    }


    public String getParameter(String parameterName) throws XMLException {
        String parameterValue = basicParameters.get(parameterName);

        if (parameterValue == null)
            throw new XMLException("Unset parameter: " + parameterName);
        return parameterValue;
    }


    public HashMap<String, String> getMapParameter(String parameterName)
            throws XMLException {
        HashMap<String, String> mapParameter = mapParameters.get(parameterName);

        if (mapParameter == null)
            throw new XMLException("Unset parameter map: " + parameterName);

        return mapParameter;
    }

}
